﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Base.DAL;
using Base.BLL;
using Base.Util;
using System.ComponentModel;
using MPSystem.Models;
using Ay.Framework.WPF;
using System.Data;
using ADX.Views;

namespace MPSystem.Views.YFQ
{
    /// <summary>
    /// WYYLHistory_Condition.xaml 的交互逻辑
    /// </summary>
    public partial class WYYLHistory_Condition : Page
    {
        public Dictionary<string, string> Cond = new Dictionary<string, string>();
        public static WYYLHistory_Condition _Me = null;
        public static WYYLHistory_Condition Me
        {
            get
            {
                if (_Me == null)
                {
                    _Me = new WYYLHistory_Condition();
                    _Me.UpdateCond();
                }
                return _Me;
            }
            set { _Me = value; }
        }
        int xdbh = 0;

        public WYYLHistory_Condition()
        {
            InitializeComponent();
            LoadData();
            Me = this;
        }


        public void LoadData()
        {
            #region 加载加权
            string strJQ = "0&连续,2&2H,4&4H,8&8H,12&12H,24&24H";
            string[] arJQ = strJQ.Split(',');
            DataTable tempTable = new DataTable();
            DataColumn dc1 = new DataColumn("bh", Type.GetType("System.Int32"));
            DataColumn dc2 = new DataColumn("mc", Type.GetType("System.String"));
            tempTable.Columns.Add(dc1);
            tempTable.Columns.Add(dc2);
            foreach (var r in arJQ)
            {
                string[] arrl = r.ToString().Split('&');
                DataRow dr0 = tempTable.NewRow();
                dr0["bh"] = int.Parse(arrl[0]);
                dr0["mc"] = arrl[1].ToString();
                tempTable.Rows.Add(dr0);
            }
            tempTable.AcceptChanges();
            CB_Time.ItemsSource = tempTable.DefaultView;
            CB_Time.SelectedIndex = 0;
            tempTable.Dispose();
            #endregion

            LoadBH();
            Begtime.Date = DateTime.Now.Date;
            Endtime.Date = DateTime.Now.Date + new TimeSpan(23, 59, 59);
        }

        #region 读取传感器列表
        public void LoadBH()
        {
            if (xdbh == ZCYLPage_WYYL_History.xdbh) return;
            CB_Cgq.Items.Clear();
            xdbh = ZCYLPage_WYYL_History.xdbh;
            var bhs = ConfigService.GetCqylWz(ZCYLPage_WYYL_History.xdbh);
            foreach (var bh in bhs)
            {
                CB_Cgq.Items.Add(bh.CGQBH);
            }
            if (bhs.Count() > 0)
                CB_Cgq.SelectedIndex = 0;
        }
        #endregion

        public void UpdateCond()
        {
            Cond.Clear();
            try
            {
                if (CB_Cgq.SelectedIndex == -1)
                {
                    AyMessageBox.ShowError("传感器必须选择！");
                    return;
                }
                
                Cond.Add("bh", CB_Cgq.SelectedValue.ToObjectString());
                Cond.Add("dtStart", Begtime.Text.ToString());
                Cond.Add("dtEnd", Endtime.Text.ToString());
                Cond.Add("jq", CB_Time.SelectedValue.ToString());//加权
            }
            catch { }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.CloseParentWindow();
        }
    }
}
